package main

import (
	"fmt"
	"os"
	"strconv"
	"time"
)

func say(s string) {
	for i := 0; i < 5; i++ {
		time.Sleep(100 * time.Millisecond)
		fmt.Println(s)
	}
}

/*全局变量*/
var (
	e int
	f bool = true
)

/*枚举-全局常量*/
const (
	Unknown = 0
	Female  = 1
	Male    = 2
)

/*枚举-特殊常量iota*/
const (
	ca = iota
	cb
	cc
	cd = "world"
	ce
)

func main() {
	// hello world
	var param1 string
	if len(os.Args) > 1 {
		fmt.Println(os.Args[1])
		fmt.Println("Hello, World!")
		param1 = os.Args[1]
	}

	/****【变量】****/
	// 变量-1：正常写法
	var num1 int
	num1 = 10
	fmt.Printf("num1 = %v \n", num1)

	// 变量-2：声明类型和自动识别类型
	var num2 = 99
	var num22 int = 999
	fmt.Printf("num2 = %v, num22 = %v \n", num2, num22)

	// 变量-3：声明+赋值 (不带声明格式的只能在函数体中出现)
	var num3 = 1000
	num33 := 100
	fmt.Printf("num3 = %v, num33 = %v \n", num3, num33)

	// 变量-4：变量缺省值
	var num int32
	var big_num float64
	var isOk bool
	var str string
	var ary []int
	fmt.Printf("整数：%v,浮点数：%v,布尔：%v,字符串：%q,数组：%v \n", num, big_num, isOk, str, ary)

	// 变量-5：多变量赋值
	var x, y int = 100, 1000
	a, b := 1, 2
	var c, d = "hello", 321
	fmt.Printf("a: %v,b：%v,c：%q,d：%v,e：%v,f：%v \n", a, b, c, d, e, f)
	fmt.Println(x + y)

	// 变量-5：值类型和引用类型
	var v1 = 123
	var v2 = v1
	fmt.Println(&v1, &v2)

	/***【常量】***/
	const c1, c2 string = "hello", "你好"
	const c3, c4 = 123, true
	fmt.Printf("c1=%v, c2=%v, c3=%v, c4=%v, Female=%v \n", c1, c2, c3, c4, Female)
	fmt.Printf("ca=%v, cb=%v, cc=%v, cd=%v, ce=%v \n", ca, cb, cc, cd, ce)

	/***【运算符】***/
	// 算数、关系、逻辑、位、赋值、指针

	/***【条件语句】***/
	i, err := strconv.ParseInt(param1, 10, 64)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Println("Converted integer:", i)
	if i < 10 {
		fmt.Println("i的值小于10")
	} else if i < 100 {
		fmt.Println("i的值小于100，大于10")
	} else {
		fmt.Println("i的值大于100")
	}

	/***【循环语句】***/
	// for-i
	sum := 0
	for i := 0; i <= 10; i++ {
		sum += i
	}
	fmt.Println(sum)
	// 相当于while循环
	count := 1
	for count <= 10 {
		count += count
	}
	fmt.Println(count)

	// for-each
	strs := []string{"tom", "jerry", "lily"}
	for idx, item := range strs {
		fmt.Printf("索引：%v, 值： %q \n", idx, item)
	}
	numbers := [6]int{1, 2, 3, 5}
	for i, x := range numbers {
		fmt.Printf("第 %d 位 x 的值 = %d\n", i, x)
	}
	// break/continue/goto语句
	j := 0
	for j < 10 {
		if j == 7 {
			goto LOOP
		}
		j++
	}
LOOP:
	fmt.Println(j)

}
